package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.component.Variate;
import com.github.aloxc.plugin.restplus.component.VariateTableModel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class VariateDeleteListener implements ActionListener {
    private Variate variate;

    public VariateDeleteListener(Variate variate) {
        this.variate = variate;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        VariateTableModel model = (VariateTableModel) variate.getVariateTable().getModel();
        java.util.List<Integer> removeList = new ArrayList<>();
        for (int rowIndex = 0; rowIndex< model.getRowCount();rowIndex++){
            boolean value = (Boolean) model.getValueAt(rowIndex, 4);
            if(value){
                removeList.add(rowIndex);
            }
        }
        model.removeRows(removeList);
    }
}
